package com.youth.youthservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youth.youthservice.entity.EduCourseCollect;
import com.youth.youthservice.entity.vo.CourseVo.CourseCollectVo;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @Author：CM
 * @Package：com.youth.youthservice.mapper
 * @Project：youth-college
 * @name：EduCourseCollectMapper
 * @Date：2023/5/5 13:08
 * @Filename：EduCourseCollectMapper
 */
public interface EduCourseCollectMapper extends BaseMapper<EduCourseCollect> {

    /*根据用户id查询出对应的课程id集合*/
    @MapKey(value = "id")
    List<Map<String,String>> getIdsMap(String userId);

    @Select("select teacher_id from edu_course where id = #{courseID}")
    String getTeacherIdByCourseId(String courseId);

    /*建立两表联查，根据用户id查询出对应的课程信息和收藏id*/
    List<CourseCollectVo> courseCollectList(String userId);

    @Update("update edu_course_collect set top = \n" +
            "case when top = 0 then 1 else 0 end\n" +
            "where id = #{id}")
    void setTopCollects(String id);
}
